﻿@using Coslen.Framework.Helpers
@using Coslen.TahorCRM.Domain.Entities.ViewModels.Editing
@model Coslen.TahorCRM.Domain.Entities.ViewModels.Editing.ContactEditViewModel
@{
    ViewBag.Title = "Edit";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@section HeaderIncludes
{
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
    <script src="@Url.Content("~/Scripts/gmap3.min.js")" type="text/javascript"></script>
}

<script type="text/javascript" language="javascript ">
    $(document).ready(function () {

    });

    function setupMap() {
        $("#googleGMap").gmap3(
        {
            action: 'clear'
        },
        {
            action: 'addMarker',
            address: "27 Maude Street, Belmont. NSW 2280",
            map: {
                center: true,
                zoom: 14
            },
            infowindow: {
                options: {
                    content: 'Belmont Baptist Church'
                }
            }
        });
    }

    function handleTabEvents(event, ui) {
        // Objects available in the function context:
        //        ui.tab     // anchor element of the selected (clicked) tab
        //        ui.panel   // element, that contains the selected/clicked tab contents
        //        ui.index   // zero-based index of the selected (clicked) tab
        if (ui.index == 1) {
            setupMap();

            // Must Reappply  the menus
            $("#jMenu").jMenu();
        }
    };

    function centerMap(address) {

        $("#googleGMap").gmap3(
        {
            action: 'clear'
        },
        {
            action: 'addMarker',
            address: address,
            map: {
                center: true,
                zoom: 14
            }
        });

        google.maps.event.trigger($('#googleGMap').gmap3("get"), "resize");
        
        // Must Reappply  the menus
        $("#jMenu").jMenu();
    }
  
</script>
<h2>Contact Information</h2>

@if (Model.sourceUrl != null && Model.sourceUrl.Contains("/Contacts/Address"))
{
    <script type="text/javascript">
        $(function() {
            var tabOpts = {  
                select:handleTabEvents,
                selected: 1           
            };  
            $("#tabs").tabs(tabOpts);
        });
    </script> 
}
else if (Model.sourceUrl != null && Model.sourceUrl.Contains("/Contacts/ContactDetail"))
{
    <script type="text/javascript">
        $(function() {
            var tabOpts = {  
                select:handleTabEvents,
                selected: 2          
            };  
            $("#tabs").tabs(tabOpts);
        });
    </script> 
}
else if (Model.sourceUrl != null && Model.sourceUrl.Contains("/Contacts/ContactRelationship"))
{
    <script type="text/javascript">
        $(function () {
            var tabOpts = {
                select: handleTabEvents,
                selected: 3
            };
            $("#tabs").tabs(tabOpts);
        });
    </script> 
}
else if (Model.sourceUrl != null && Model.sourceUrl.Contains("/Contacts/ContactEvent"))
{
    <script type="text/javascript">
        $(function () {
            var tabOpts = {
                select: handleTabEvents,
                selected: 4
            };
            $("#tabs").tabs(tabOpts);
        });
    </script> 
}
else if (Model.sourceUrl != null && Model.sourceUrl.Contains("/Contacts/Note"))
{
    <script type="text/javascript">
        $(function () {
            var tabOpts = {
                select: handleTabEvents,
                selected: 5
            };
            $("#tabs").tabs(tabOpts);
        });
    </script> 
}
else
{
    <script type="text/javascript">
        $(function() {
            var tabOpts = {  
                select:handleTabEvents,
                selected: 0          
            };  
            $("#tabs").tabs(tabOpts);
        });
    </script> 
}

<fieldset>
    <div id="tabs">
        <ul>
            <li><a href="#tab_1">Details</a></li>
            <li><a href="#tab_2">Addresses</a></li>
            <li><a href="#tab_3">Contact Details</a></li>
            <li><a href="#tab_4">Contact Relationships</a></li>
            <li><a href="#tab_5">Events</a></li>
            <li><a href="#tab_6">Notes</a></li>
        </ul>
        <div id="tab_1" class="content">
                
            @Html.Partial("_DetailsOrDelete", Model)
            @Html.HiddenFor(x => x.sourceUrl)
            @if (User.IsInRole("CanEditContact"))
            {
                <p>
                    @Html.ImageActionLink(
                        Url.Content("~/Content/Images/add.png"),
                        "Edit the contact",
                        "Edit",
                        "Edit",
                        "Contact",
                        new {area = "Contacts", source = "Contact:Details:" + Model.Contact.ContactId, id = Model.Contact.ContactId},
                        new {@class = "actionLink"},
                        new {@class = "actionIconMedium"})
                </p>
            }
        </div>
        <div id="tab_2" class="content">
            <div class="address_DisplayLine address_DisplayLineHeader">
                <div class="info">
                    Address
                </div>
                <div class="type">
                    Type
                </div>
                <div class="displaybool">
                    Primary
                </div>
                <div class="displaybool">
                    Do Not Use
                </div>
                <div class="tool">
                    Actions
                </div>
            </div>
            @Html.DisplayFor(model => model.Addresses)
            <div class="address_DisplayLine address_DisplayLineFooter">
                @if (User.IsInRole("CanEditContact"))
                {
                    @Html.ImageActionLink(
                        Url.Content("~/Content/Images/add.png"),
                        "Create New Address",
                        "Add New",
                        "Create",
                        "Address",
                        new {area = "Contacts", source = "Contact:Details:" + Model.Contact.ContactId, entityLinkId = Model.Contact.EntityLinks.First().EntityLinkId},
                        new {@class = "actionLink"},
                        new {@class = "actionIcon"})
                }
            </div>
            <div id="googleGMap"></div>
        </div>
        <div id="tab_3" class="content">
            <div class="contactDetail_DisplayLine contactDetail_DisplayLineHeader">
                <div class="info">
                    Contact Detail
                </div>
                <div class="type">
                    Type
                </div>
                <div class="displaybool">
                    Primary
                </div>
                <div class="displaybool">
                    Do Not Use
                </div>
                <div class="tool">
                    Actions
                </div>
            </div>
            @Html.DisplayFor(model => model.ContactDetails)
            <div class="contactDetail_DisplayLine contactDetail_DisplayLineFooter">
                @if (User.IsInRole("CanEditContact"))
                {
                    @Html.ImageActionLink(
                        Url.Content("~/Content/Images/add.png"),
                        "Create New Contact Detail",
                        "Add New",
                        "Create",
                        "ContactDetail",
                        new {area = "Contacts", source = "Contact:Details:" + Model.Contact.ContactId, entityLinkId = Model.Contact.EntityLinks.First().EntityLinkId},
                        new {@class = "actionLink"},
                        new {@class = "actionIcon"})
                }
            </div>
        </div>
        <div id="tab_4" class="content">
            <div class="contactRelationship_DisplayLine contactRelationship_DisplayLineHeader">
                <div class="info">
                    Contact
                </div>
                <div class="type">
                    Relationship
                </div>
                <div class="tool">
                    Actions
                </div>
            </div>
            @Html.DisplayFor(model => model.Contact.PrimaryContactRelationships)
            <div class="contactRelationship_DisplayLine contactRelationship_DisplayLineFooter">
                @if (User.IsInRole("CanEditContact"))
                {
                    @Html.ImageActionLink(
                        Url.Content("~/Content/Images/add.png"),
                        "Create New Relationship",
                        "Add New",
                        "Create",
                        "ContactRelationship",
                        new {area = "Contacts", source = "Contact:Details:" + Model.Contact.ContactId, primaryContactId = Model.Contact.ContactId},
                        new {@class = "actionLink"},
                        new {@class = "actionIcon"})
                }
            </div>
        </div>
        <div id="tab_5" class="content">
            <div class="history_DisplayLine history_DisplayLineHeader">
                <div class="info">
                    Event Date
                </div>
                <div class="type">
                    Type
                </div>
                <div class="tool">
                    Actions
                </div>
            </div>
            @Html.DisplayFor(model => model.Contact.ContactEvents)
            <div class="history_DisplayLine history_DisplayLineFooter">
                @if (User.IsInRole("CanEditContact"))
                {
                    @Html.ImageActionLink(
                        Url.Content("~/Content/Images/add.png"),
                        "Create New Event",
                        "Add New",
                        "Create",
                        "ContactEvent",
                        new {area = "Contacts", source = "Contact:Details:" + Model.Contact.ContactId, contactId = Model.Contact.ContactId},
                        new {@class = "actionLink"},
                        new {@class = "actionIcon"})
                }
            </div>
        </div>
        <div id="tab_6" class="content">
            <div class="DisplayLine DisplayLineHeader">
                <div class="type">
                    Entered By
                </div>
                <div class="displayDate">
                    Entered At
                </div>
                <div class="type">
                    Type
                </div>
                <div class="displaybool">
                    Is Public
                </div>
                <div class="tool">
                    Actions
                </div>
            </div>
            @Html.DisplayFor(model => model.ContactNotes)
            <div class="DisplayLine DisplayLineFooter">
                @if (User.IsInRole("CanEditContact"))
                {
                    @Html.ImageActionLink(
                        Url.Content("~/Content/Images/add.png"),
                        "Create New Note",
                        "Add New",
                        "Create",
                        "Note",
                        new {area = "Contacts", source = "Contact:Details:" + Model.Contact.ContactId, entityLinkId = Model.Contact.EntityLinks.First().EntityLinkId},
                        new {@class = "actionLink"},
                        new {@class = "actionIcon"})
                }
            </div>
        </div>
    </div>
</fieldset>



<div>
    @Html.ActionLink("Back to List", "Index")
</div>
